package com.caogen.cg_wl_kt.base

import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.viewbinding.ViewBinding
import com.caogen.cg_wl_kt.R
import com.caogen.cg_wl_kt.utils.ToastUtils
import com.quansu.trailertiger.base.BActivity

/**
 * 项目名称: cg_wl_kt
 * Packages:com.caogen.cg_wl_kt.base
 * author: FSW
 * 创建日期: 2024/2/28 11:29
 * Describe:
 *
 */
open class BaseActivity < VB : ViewBinding,VM : BaseViewModel>(
    inflater: (LayoutInflater) -> VB,
    clazz: Class<VM>
): BActivity<VB,VM> (inflater,clazz) {

    var toolbar:Toolbar? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        toolbar = findViewById(R.id.toolbar)
        if (null != toolbar) {
            toolbar?.setNavigationIcon(R.drawable.arad_ic_back_normal)
            toolbar?.setNavigationOnClickListener(this)
            toolbar?.title = ""
        }
        initView()
    }

    override fun initView() {
        super.initView()

    }

    override fun onClick(v: View?) {
        super.onClick(v)
        if (v!!.id == -1) { //点击的是toolbar左上角的按钮
            onBackPressed()
        }
    }

    protected open fun setNavigationIcon(iconId: Int) {
        if (null != toolbar) {
            toolbar!!.setNavigationIcon(iconId)
        }
    }
    protected open fun setNoNavigationIcon() {
        if (null != toolbar) {
            toolbar!!.navigationIcon = null
        }
    }

    open fun toast(msg: String?) {
        if (!TextUtils.isEmpty(msg)) {
            ToastUtils.showShortSafe(msg)
        }
    }
}